from ZSI.auth import AUTH
from ZSI import client

# Web-Service Locator
class Homebuh_Web_ServiceLocator:
    HomebuhService_Port_address = "https://localhost:8443/HomebuhService"
    def getHomebuhService_PortAddress(self):
        return Homebuh_Web_ServiceLocator.HomebuhService_Port_address
    def getHomebuhService_Port(self, url=None, **kw):
        return HomebuhService_BindingSOAP(url or Homebuh_Web_ServiceLocator.HomebuhService_Port_address, **kw)

# Methods
class HomebuhService_BindingSOAP:
    def __init__(self, url, **kw):
        kw.setdefault("readerclass", None)
        kw.setdefault("writerclass", None)
        # no resource properties
        if (("login" in kw) and ("psswd" in kw)):
            kw["auth"] = [AUTH.httpbasic, kw["login"], kw["psswd"]]
        self.binding = client.Binding(url=url, **kw)
        # no ws-addressing

    def setBasicHTTPAuthentication(self, login, password):
        self.login = login
        self.password = password

    # op: login
    def login(self, request, **kw):
        from services.SOAPServicesAgent import loginResponse
        # no input wsaction
        self.binding.Send(None, None, request, soapaction="urn:HomebuhService.wsdl#login", **kw)
        # no output wsaction
        response = self.binding.Receive(loginResponse.typecode)
        return response

    # op: registerAccount
    def registerAccount(self, request, **kw):
        from services.SOAPServicesAgent import registerAccountResponse
        # no input wsaction
        self.binding.Send(None, None, request, soapaction="urn:HomebuhService.wsdl#registerAccount", **kw)
        # no output wsaction
        response = self.binding.Receive(registerAccountResponse.typecode)
        return response

    # op: getAccounts
    def getAccounts(self, request, **kw):
        from services.SOAPServicesAgent import getAccountsResponse
        # no input wsaction
        self.binding.Send(None, None, request, soapaction="urn:HomebuhService.wsdl#getAccounts", **kw)
        # no output wsaction
        response = self.binding.Receive(getAccountsResponse.typecode)
        return response
